import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { AiAlarmApi } from '#/api/moxi/aialarm';
import Dayjs from 'dayjs';

import {
  getRangePickerDefaultProps,
} from '#/utils';

/** 新增/修改的表单 */

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'streamNickname',
      label: '抓拍摄像头名称',
      component: 'Input',
      componentProps: {
        placeholder: '请输入抓拍摄像头名称',
        allowClear: true,
      },
    },
    {
      fieldName: 'alarmTime',
      label: '违规时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns<T = AiAlarmApi.AiAlarm>(
  onStatusChange?: (
    newStatus: number,
    row: T,
  ) => PromiseLike<boolean | undefined>,
): VxeTableGridOptions['columns'] {
  return [
    {
      field: 'id',
      title: '序号',
    },
    {
        field: 'streamCode',
        title: '摄像头编号',
    },
    {
        field: 'streamNickname',
        title: '摄像头名称',
    },
    {
        field: 'alarmTime',
        title: '抓拍时间',
        formatter: ({ cellValue }) => {
          return cellValue?Dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '';
        },
    },
    {
        field: 'className',
        title: '抓拍目标',
    },
    {
      title: '操作',
      width: 180,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
